<?php

namespace plugin\admin\app\controller\admin;

use plugin\admin\app\controller\AuthController;
use plugin\admin\app\logic\admin\RoleLogic;
use support\exception\BusinessException;
use support\Request;
use support\Response;
use Throwable;

/**
 * 角色管理
 */
class RoleController extends AuthController
{
    /**
     * 浏览
     * @return Response
     * @throws Throwable
     */
    public function index(): Response
    {
        return raw_view('role/index');
    }

    /**
     * 查询
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function select(Request $request): Response
    {
        return RoleLogic::getInstance()->select($request);
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     * @throws Throwable
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return RoleLogic::getInstance()->insert($request);
        }
        return raw_view('role/insert');
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException|Throwable
     */
    public function update(Request $request): Response
    {
        if ($request->method() === 'GET') {
            return raw_view('role/update');
        }
        return RoleLogic::getInstance()->update($request);
    }

    /**
     * 删除
     * @param Request $request
     * @return Response
     * @throws BusinessException
     * @throws \plugin\admin\app\exception\AdminException
     */
    public function delete(Request $request): Response
    {
        return RoleLogic::getInstance()->delete($request);
    }

    /**
     * 获取角色权限
     * @param Request $request
     * @return Response
     */
    public function rules(Request $request): Response
    {
       return RoleLogic::getInstance()->rules($request);
    }




}
